package com.example.qxfw.qxybzz.service.Impl;

import com.example.qxfw.qxybzz.entity.PageBean;
import com.example.qxfw.qxybzz.entity.dto.PersonDto;
import com.example.qxfw.qxybzz.entity.vo.PersonVo;
import com.example.qxfw.qxybzz.mapper.PublishObjectMapper;
import com.example.qxfw.qxybzz.service.PublishObjectService;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
@RequiredArgsConstructor
public class PublishObjectServiceImpl implements PublishObjectService {

    private final PublishObjectMapper publishObjectMapper;

    @Override
    public PageBean getPagePerson(PersonDto personDto, Integer page, Integer pageSize) {
        //设置分页参数：
        PageHelper.startPage(page, pageSize);

        String name = personDto.getName();
        String workplace = personDto.getWorkPlace();
        String keyword = personDto.getKeyword();

        List<PersonVo> person =publishObjectMapper.getPagePerson(name, workplace, keyword);
        Page<PersonVo> pagePerson = (Page<PersonVo>) person;

        PageBean pageBean = new PageBean(pagePerson.getTotal(), pagePerson.getResult());
        return pageBean;
    }

    /**
     * 根据id删除人员
     * @param id
     */
    @Override
    public void deletePerson(Integer id) {
        publishObjectMapper.deletePerson(id);
    }

    /**
     * 批量删除人员
     * @param ids
     */
    @Override
    public void deletePersons(Integer[] ids) {
        publishObjectMapper.deletePersons(ids);
    }

    /**
     * 新增人员
     *
     * @param personDto
     */
    @Override
    public void addPerson(PersonDto personDto) {
        String name = personDto.getName();
        String workPlace = personDto.getWorkPlace();
        String position = personDto.getPosition();
        String phone = personDto.getPhone();
        publishObjectMapper.addPerson(name, workPlace, position, phone);
    }

    /**
     * 修改人员信息
     *
     * @param personDto
     */
    @Override
    public void updatePerson(PersonDto personDto) {
        publishObjectMapper.updatePerson(personDto);
    }


}
